<?php

/*
 *
 *  get_features returns a feature array for a specific ( file, algorithm ) pair
 *
 */

function get_features( $file, $algo = 0 , $full = false ){
  $a = array();
  $filepgm = sha1($file) . ".pgm";
  $sz = 120;

  switch($algo){
   case 0:
// canny filter feature detection
    exec( "convert \"$file\" -resize " . $sz . "x" . $sz . "^ -auto-level -gravity center -crop 120x120+0+0 \"$filepgm\" ; ./fast-edge \"$filepgm\" \"$filepgm\" " );
   break;
   case 1:
// gaussian difference feature detection
    exec( "convert \"$file\" -resize " . $sz . "x" . $sz . "^ -auto-level -gravity center -edge 1 -crop 120x120+0+0 \"$filepgm\"" );
   break;
  }
  exec( "./process \"$filepgm\" ; rm -f \"$filepgm\"" , $a );

  return $a;
}

function get_pgm( $file ){
  $filepgm = sha1($file) . ".pgm";
  exec( "convert \"$file\" -resize 120x120^ -auto-level -gravity center -crop 120x120+0+0 \"$filepgm\" ; ./fast-edge \"$filepgm\" \"$filepgm\" " );
  $ret = file_get_contents($filepgm);
  exec("rm \"$filepgm\"");
  return $ret;
}

function get_features_by_pgm( $pgm ){
  $fn = sha1($pgm) . ".pgm";
  file_put_contents( $fn, $pgm );
  $a = array();
  exec( "./process \"$fn\" ; rm -f \"$fn\"" , $a );
  return $a;
}

?>
